<%@page language="java" contentType="text/html"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@page import="java.util.ArrayList"%>
<%@ page import="java.util.*" %>
<%@ page import="Personal.Person" %>
<%@ page import="Personal.Doctor" %>
<%@ page import="Personal.Patient" %>
<%@ taglib uri="/WEB-INF/hospital.tld" prefix="hosp"%>
<fmt:setBundle basename="hospital"/>
<html>
<head>
<title>Patients tasks</title>

</head>



<jsp:useBean id="displayedUser" scope="request" class="Patient"/>

<h2> <fmt:message key="patient"/>.  <fmt:message key="name"/> : ${displayedUser.name}</h2>
<h2 align = "center"><fmt:message key="intakes"/></h2>
<table border="1">
   <tr width="100%">
        <td width= "50%"><fmt:message key="date"/></td>
        <td width = "20%"><fmt:message key="doctor"/></td>
        <td width= "50%"><fmt:message key="comment"/></td>
   </tr>
<c:forEach var="intake" items="${displayedUser.intakes}">
   <tr>
       <td> <fmt:formatDate type="date" value="${intake.date}"/> </td>
       <td> <a href="/show.do?id=${intake.doctor.idPerson}">${intake.doctor.name}</a> </td>
       <td>  ${intake.comment}  </td>
       <td>
           <hosp:hasRights user = "${displayedUser}">
                <a href = "/addIntake.jsp?id=${displayedUser.idPerson}?idIntake=${intake.id}"><fmt:message key="edit"/></a>
                <a href = "/delIntake.do?idIntake=${intake.id}"><fmt:message key="remove"/></a>
            </hosp:hasRights>
       </td>
   </tr>
</c:forEach>
</table>

<hosp:hasRights user = "${displayedUser}">
    <a href = "/addIntake.jsp?id=${displayedUser.idPerson}"> <fmt:message key="addIntake"/></a>
</hosp:hasRights>

<h2 align = "center"><fmt:message key="prescriptions"/></h2>

<c:forEach var="prescription" items="${displayedUser.prescriptions}">
<fieldset>
<h3><fmt:message key="doctor_set_prescription"/>  <a href="/show.do?id=${prescription.doctor.idPerson}">${prescription.doctor.name}</a></h3>
<h3><fmt:message key="operations"/></h3>
   <table border="1">
   <tr width="100%">
        <td width= "50%"><fmt:message key="date"/></td>
        <td width= "20%"><fmt:message key="Cabinet"/></td>
        <td width= "70%"><fmt:message key="OperationName"/></td>
        <td width= "20%"><fmt:message key="patient"/></td>
        <td width= "50%"><fmt:message key="doctors"/></td>
   </tr>
    <c:forEach var="operation" items="${prescription.operations}">
       <tr>
           <td> <fmt:formatDate type="date" value="${intake.date}"/> </td>
           <td>  ${operation.cabinetNumber}  </td>
           <td>  ${operation.name}  </td>
           <td align = "center"> <a href="/show.do?id=${operation.prescription.patient.idPerson}">${operation.prescription.patient}</a> </td>

           <td>
                <ul >
                <c:forEach var="doctor" items="${operation.doctors}">
                    <li align = "left">
                        <a href="/show.do?id=${doctor.idPerson}">${doctor.name}</a>
                    </li>
                </c:forEach>
                </ul>
           </td>
       </tr>
    </c:forEach>
    </table>
<hosp:hasRights user = "${displayedUser}">
    <a href = "/addOperation.jsp?id=${displayedUser.idPerson}"><fmt:message key="add_operation"/></a>
</hosp:hasRights>
<h3><fmt:message key="drugs"/></h3>
   <table border="1">
   <tr width="100%">
        <td width= "50%"><fmt:message key="drugs_name"/></td>
        <td width= "20%"><fmt:message key="weigth"/></td>
        <td width= "70%"><fmt:message key="period"/></td>
        <td width= "20%"><fmt:message key="term"/></td>
        <td width= "50%"><fmt:message key="category"/></td>
   </tr>
<c:forEach var="drugDose" items="${prescription.drugDoses}">
   <tr>
       <td>  ${drugDose.drugs.name}  </td>
       <td>  ${drugDose.weigth}  </td>
       <td>  ${drugDose.period}  </td>
       <td>  &{drugDose.term}</td>
       <td>  &{drugDose.drugs.cathegory}</td>
   </tr>
<br>
<br>
</c:forEach>
</table>
<hosp:hasRights user = "${displayedUser}">
    <a href = "/addDrugs.jsp?id=${displayedUser.idPerson}"><fmt:message key="add_drugs"/></a>
</hosp:hasRights>
</fieldset>
</c:forEach>
</table>

</body>
</html>